﻿
@{
    ViewBag.Title = "AccountingExecutionQuery";
    Layout = "~/Views/Shared/_Form.cshtml";

    var reqFrom = HttpContext.Current.Request.QueryString["from"];
}

<form name="form1">
    <div class="panel panel-default">
        <div class="panel-heading navb-bg">
            筛选条件
        </div>
        <div style="padding: 2px;padding-right:20px;">
            <table class="form">
                <tr>
                    <th class="formTitle">撤销状态：</th>
                    <td class="formValue">
                        <select id="cxzt" name="cxzt" class="form-control">
                            <option value="">==全部==</option>
                            <option value="0">已撤销</option>
                            <option value="1">正常</option>
                        </select>
                    </td>
                    @if (!(reqFrom == "mz"))
                    {
                        <th class="formTitle">收费状态：</th>
                        <td class="formValue">
                            <select id="sfzt" name="sfzt" class="form-control">
                                <option value="">==全部==</option>
                                <option value="0">未收费</option>
                                <option value="1">已收费</option>
                            </select>
                        </td>
                    }
                    <th class="formTitle">治疗师：</th>
                    <td class="formValue">
                        <select id="zls" name="zls" class="form-control">
                            <option value="">==全部==</option>
                        </select>
                    </td>
                    <th class="formTitle">关键字：</th>
                    <td class="formValue" style="width:145px;">
                        <input type="text" style="width:145px;" class="form-control" id="keyword" placeholder="" />
                    </td>
                    @if (reqFrom == "mz")
                    {
                        <th class="formTitle">操作时间：</th>
                        <td class="formValue" colspan="2">
                            <input id="kssj" type="text" class="form-control input-wdatepicker" style="width:42%; float:left;" value="@DateTime.Now.ToString("yyyy-MM-01")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                            <span style="margin-left:1%;float:left">—</span>
                            <input id="jssj" type="text" class="form-control input-wdatepicker" style="width:43%; float:left;margin-left:1%;" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                        </td>
                        <td class="formValue">
                            <input type="button" id="btn_search" class="btn btn-primary" style="width:36%;margin-left: 10%;" value="查询" />
                        </td>
                    }
                </tr>
                @if (!(reqFrom == "mz"))
                {
                    <tr>
                        <th class="formTitle">操作时间：</th>
                        <td class="formValue" colspan="2">
                            <input id="kssj" type="text" class="form-control input-wdatepicker" style="width:42%; float:left;" value="@DateTime.Now.ToString("yyyy-MM-01")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                            <span style="margin-left:1%;float:left">—</span>
                            <input id="jssj" type="text" class="form-control input-wdatepicker" style="width:43%; float:left;margin-left:1%;" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                        </td>
                        <td class="formValue">
                            <input type="button" id="btn_search" class="btn btn-primary" style="width:36%;margin-left: 10%;" value="查询" />
                        </td>
                    </tr>
                }
            </table>
        </div>
    </div>
    <div class="gridPanel">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
</form>
@Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel()
{
    ShowKeyList = new int[] { 9 },
    F9Text = "导出Excel",
})
<script>
    var from = $.request("from");
    if (!!!from) {
        from = "zy";
    }
    if (from === 'mz') {
        $('#keyword').attr('placeholder', '患者姓名/病历号/门诊号');
    }
    else {
        $('#keyword').attr('placeholder', '患者姓名/病历号/住院号');
    }

    $(function () {
        $("#zls").bindSelect({
            url: "/SystemManage/Staff/GetStaffByDutyCode?dutyCode=" + "RehabDoctor",
            id: "StaffGh",
            text: "StaffName"
        });

        //撤销状态 自动触发查询
        $('#cxzt').change(function () {
            $('#btn_search').trigger('click');
        });

        //收费状态 自动触发查询
        $('#sfzt').change(function () {
            $('#btn_search').trigger('click');
        });

        //治疗师切换 自动触发查询
        $('#zls').change(function () {
            $('#btn_search').trigger('click');
        });

        gridList();
    });

    //明细
    var gridOptins = {
        url: "/HospitalizationManage/BookkeepInHos/GetAccountingExecutionQuery",
        postData: getSearchPostData(),
        height: $(window).height() - (from == "mz" ? 200 : 225),
        colModel: [
        { label: "zxjlId", name: "zxjlId", width: 100, align: "left", hidden: true },
        { label: "治疗师", name: "zlsmc", width: 80, align: "left" },
        {
            label: "状态", name: "zt", width: 40, align: "left",
            formatter: function (cellvalue, a, b) {
                if (cellvalue == '1') {
                    return "正常"
                }
                else {
                    return "已撤销";
                }
            }
        },
        {
            label: "收费状态", name: "sfzt", width: 60, align: "left",
            hidden: (from == "mz" ? true : undefined),
            formatter: function (cellvalue) {
                if (cellvalue == '1') {
                    return "已收费"
                }
                else if (cellvalue == '0') {
                    return "未收费";
                }
                return "";
            }
        },
        { label: "患者姓名", name: "xm", width: 70, align: "left" },
        { label: "病历号", name: "blh", width: 70, align: "left" },
        { label: (from == "mz" ? "门诊号" : "住院号"), name: "mzzyh", width: (from == "mz" ? 100 : 70), align: "left" },
        {
            label: "康复类别", name: "kflb", width: 60, align: "left",
            formatter: function (cellvalue) {
                return $.itemDetails.getNameByCode("RehabTreatmentMethod", cellvalue);
            }
        },
        { label: "收费项目", name: "sfxmmc", width: 180, align: "left" },
        { label: "治疗量", name: "zll", width: 40, align: "left" },
        { label: "单位", name: "dw", width: 40, align: "left" },
        { label: "数量", name: "sl", width: 50, align: "left" },
        {
            label: "单价", name: "dj", width: 55, align: "left", formatter: "number"
                , formatoptions: { decimalPlaces: 2, defaultValue: '0.00' }
        },
        {
            label: "报销政策", name: "zfxz", width: 60, align: "left",
            formatter: function (cellvalue) {
                return $.enum.getDescByValue("EnumZiFuXingZhi", cellvalue);
            }
        },
        {
            label: "金额", name: "je", width: 55, align: "left", formatter: "number"
                , formatoptions: { decimalPlaces: 2, defaultValue: '0.00' }
        },
        {
            label: "治疗日期", name: "zlrq", width: 80, align: "left",
            formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
            }, {label: "操作人", name: "Creater", width: 120, align: "left"},
        {
            label: "操作时间", name: "CreateTime", width: 120, align: "left",
            formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
        },
        ],
        //multiselect: true,
        pager: "#gridPager",
        sortname: 'CreateTime desc',
        viewrecords: true,
        gridComplete: function () {
            var ids = $("#gridList").getDataIDs();
            for (i = 0; i < ids.length; i++) {
                var rowData = $("#gridList").getRowData(ids[i]);
                if (rowData && rowData.zt) {
                    if (rowData.zt == "已撤销") {
                        $("#" + ids[i]).find("td").addClass('danger');
                    }
                }
            }
        },
    };
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid(gridOptins);
        $("#btn_search").click(function () {
            if ($('#kssj').val() && $('#jssj').val() && ($('#kssj').val() > $('#jssj').val())) {
                $.modalAlert("开始日期不能大于结束日期", 'warning');
                return;
            }
            $gridList.jqGrid('setGridParam',
                {
                    postData: getSearchPostData(),
                    page: 1,
                    url: "/HospitalizationManage/BookkeepInHos/GetAccountingExecutionQuery"
                }).trigger('reloadGrid');
        });
    }
    //查询条件
    function getSearchPostData() {
        var keyword = $("#keyword").val();
        var kssj = $("#kssj").val();
        var jssj = $("#jssj").val();
        var zls = $("#zls").val();
        var cxzt = $("#cxzt").val();
        var sfzt = $("#sfzt").val();
        return { keyword: keyword, kssj: kssj, jssj: jssj, zls: zls, cxzt: cxzt, sfzt: sfzt, from: from };
    };

    //导出Excel 列
    var exportCols = null;
    function newtouch_event_f9() {
        exportCols = new Array();
        var colsChooseSourceArr = new Array();
        $.each(gridOptins.colModel, function () {
            if (!(this.hidden === true)) {
                exportCols.push({ Heading: this.label, Name: this.name, Width: this.width });
                colsChooseSourceArr.push({ Heading: this.label, Name: this.name });
            }
        });
        var url = "/HospitalizationManage/BookkeepInHos/ExcelExportChooseColumns";
        var cols = JSON.stringify(colsChooseSourceArr);
        cols = encodeURIComponent(cols);
        url += "?cols=" + cols;
        $.modalOpen({
            id: "ExcelExportChooseColumns",
            title: "导出Excel",
            url: url,
            width: "600px",
            height: "350px",
            callBack: function (iframeId) {
                //结果
                var restArr = top.frames[iframeId].GetChoosedCols();
                if (!!!restArr || !!!restArr.length || restArr.length == 0) {
                    $.modalAlert("请选择导出列", 'error');
                    return false;
                }
                var isContainFilter = top.frames[iframeId].GetIsContainFilter();
                //关闭选择窗口
                $.modalClose("ExcelExportChooseColumns");
                //
                exportCols = $.jsonWhere(exportCols, function (v) {
                    var matched = false;
                    for (var iIndex = 0; iIndex < restArr.length; iIndex++) {
                        if (restArr[iIndex] == v.Name) {
                            matched = true;
                        }
                    }
                    return matched;
                });
                //导出
                Export(isContainFilter);
            }
        });
    }

    function Export(isContainFilter) {
        var url = "/HospitalizationManage/BookkeepInHos/AccountingExecutionExportExcel?r=" + Math.random();
        url += "&keyword=" + $('#keyword').val();
        url += "&kssj=" + $('#kssj').val();
        url += "&jssj=" + $('#jssj').val();
        url += "&zls=" + $('#zls').val();
        url += "&cxzt=" + $('#cxzt').val();
        url += "&sfzt=" + $('#sfzt').val();
        url += "&from=" + from;
        url += "&isContainFilter=" + isContainFilter;
        url += "&colStanWidth=" + "70";  //列宽度标准列
        var cols = JSON.stringify(exportCols);
        top.$.cookie('ExportExcelCols', cols, { path: "/" });
        //url += "&cols=" + encodeURIComponent(cols);

        window.open(url);
    }

</script>